<script setup lang="ts">
import { ref, onMounted } from 'vue';
import type { Case } from './models/Case';
import { jsonStorageService } from './services/JsonStorageService';

const cases = ref<Case[]>([]);
const loading = ref(true);

// 加载案件数据
const loadCases = async () => {
  try {
    loading.value = true;
    cases.value = await jsonStorageService.getCases();
  } catch (error) {
    console.error('加载案件失败:', error);
  } finally {
    loading.value = false;
  }
};

// 初始化时加载数据
onMounted(() => {
  loadCases();
});
</script>

<template>
  <div class="app-container">
    <header class="app-header">
      <h1>AI侦探</h1>
      <p>破解谜案，寻找真相</p>
    </header>

    <main class="app-main">
      <h2>案件列表</h2>
      
      <div v-if="loading" class="loading">
        <p>正在加载案件数据...</p>
      </div>

      <div v-else-if="cases.length === 0" class="no-cases">
        <p>暂无可用案件</p>
      </div>

      <div v-else class="case-list">
        <div 
          v-for="caseItem in cases" 
          :key="caseItem.id" 
          class="case-card"
          :class="{ 'completed': caseItem.isCompleted }"
        >
          <h3>{{ caseItem.name }}</h3>
          <p class="case-description">{{ caseItem.description }}</p>
          <div class="case-info">
            <span class="difficulty">难度: {{ '★'.repeat(caseItem.difficultyLevel) }}{{ '☆'.repeat(5 - caseItem.difficultyLevel) }}</span>
            <span class="status" v-if="caseItem.isCompleted">✓ 已完成</span>
          </div>
          <button class="view-details">查看详情</button>
        </div>
      </div>
    </main>

    <footer class="app-footer">
      <p>© 2024 AI侦探 鸿蒙应用</p>
    </footer>
  </div>
</template>

<style>
/* 全局样式重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: #f5f5f5;
  color: #333;
  line-height: 1.6;
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.app-header {
  text-align: center;
  margin-bottom: 40px;
  padding: 30px 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 10px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.app-header h1 {
  font-size: 2.5rem;
  margin-bottom: 10px;
}

.app-header p {
  font-size: 1.1rem;
  opacity: 0.9;
}

.app-main {
  margin-bottom: 40px;
}

.app-main h2 {
  margin-bottom: 20px;
  color: #4a4a4a;
  font-size: 1.8rem;
}

.loading, .no-cases {
  text-align: center;
  padding: 50px 0;
  color: #666;
}

.case-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 25px;
}

.case-card {
  background: white;
  border-radius: 10px;
  padding: 25px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  border-left: 5px solid #667eea;
}

.case-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
}

.case-card.completed {
  border-left-color: #2ecc71;
}

.case-card h3 {
  margin-bottom: 15px;
  color: #2c3e50;
  font-size: 1.4rem;
}

.case-description {
  margin-bottom: 20px;
  color: #666;
  line-height: 1.6;
}

.case-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.difficulty {
  font-weight: bold;
  color: #e67e22;
}

.status {
  color: #2ecc71;
  font-weight: bold;
}

.view-details {
  width: 100%;
  padding: 12px;
  background-color: #667eea;
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.view-details:hover {
  background-color: #5a67d8;
}

.app-footer {
  text-align: center;
  padding: 20px 0;
  color: #666;
  font-size: 0.9rem;
  border-top: 1px solid #eee;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .case-list {
    grid-template-columns: 1fr;
  }
  
  .app-header h1 {
    font-size: 2rem;
  }
  
  .app-main h2 {
    font-size: 1.5rem;
  }
}
</style>
